﻿<UserControl x:Class="tomenglertde.ResXManager.View.Visuals.LanguageConfigurationView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
             xmlns:model="urn:ResXManager.Model"
             xmlns:converters="clr-namespace:tomenglertde.ResXManager.View.Converters"
             xmlns:globalization="clr-namespace:System.Globalization;assembly=mscorlib"
             xmlns:properties="clr-namespace:tomenglertde.ResXManager.View.Properties"
             xmlns:visuals="clr-namespace:tomenglertde.ResXManager.View.Visuals"
             xmlns:styles="urn:ResXManager.Styles"
             d:DataContext="{d:DesignInstance visuals:LanguageConfigurationViewModel}">
  <UserControl.Resources>

    <ControlTemplate x:Key="LanguageControlTemplate">
      <StackPanel Orientation="Horizontal" Margin="0,2" d:DataContext="{d:DesignInstance globalization:CultureInfo}">
        <Decorator Width="2" />
        <Image Width="16" Height="16" Source="{Binding Converter={x:Static converters:CultureToImageSourceConverter.Default}}" />
        <Decorator Width="5" />
        <TextBlock Text="{Binding Name}" FontWeight="Bold" />
        <Decorator Width="5" />
        <TextBlock Text="{Binding DisplayName}" />
        <Decorator Width="10" />
      </StackPanel>
    </ControlTemplate>

    <DataTemplate x:Key="LanguageDataTemplate" DataType="{x:Type globalization:CultureInfo}">
      <Control Template="{StaticResource LanguageControlTemplate}" MouseDoubleClick="Language_MouseDoubleClick" />
    </DataTemplate>

    <DataTemplate x:Key="LanguageGroupHeaderDataTemplate" DataType="{x:Type CollectionViewGroup}">
      <Border Margin="0,5,0,0" Background="{DynamicResource {x:Static styles:ResourceKeys.BorderBrush}}">
        <Control Template="{StaticResource LanguageControlTemplate}" DataContext="{Binding Name}" Focusable="False" />
      </Border>
    </DataTemplate>

    <CollectionViewSource x:Key="CollectionViewSource" Source="{x:Static model:ResourceManager.SpecificCultures}">
      <CollectionViewSource.GroupDescriptions>
        <visuals:CultureInfoGroupDescription />
      </CollectionViewSource.GroupDescriptions>
    </CollectionViewSource>

  </UserControl.Resources>
  <DockPanel>
    <TextBlock DockPanel.Dock="Top" TextWrapping="Wrap" Margin="5" Foreground="Gray"
               Text="{x:Static properties:Resources.LanguageConfiguration_Description}" />
    <ListBox x:Name="ListBox" Style="{DynamicResource {x:Static styles:ResourceKeys.ListBoxStyle}}"
             ItemsSource="{Binding Source={StaticResource CollectionViewSource}}"
             ItemTemplate="{StaticResource LanguageDataTemplate}"
             ScrollViewer.VerticalScrollBarVisibility="Disabled"
             BorderThickness="0,1,0,0">
      <ListBox.GroupStyle>
        <GroupStyle HeaderTemplate="{StaticResource LanguageGroupHeaderDataTemplate}">
          <GroupStyle.Panel>
            <ItemsPanelTemplate>
              <WrapPanel Orientation="Vertical" />
            </ItemsPanelTemplate>
          </GroupStyle.Panel>
        </GroupStyle>
      </ListBox.GroupStyle>
    </ListBox>
  </DockPanel>
</UserControl>